package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.system.mapper.ClassManageMapper;
import com.ruoyi.system.mapper.StudentManageMapper;
import com.ruoyi.system.pojo.domain.ClassManage;
import com.ruoyi.system.pojo.domain.StudentManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TransferRecordsMapper;
import com.ruoyi.system.pojo.domain.TransferRecords;
import com.ruoyi.system.service.ITransferRecordsService;

import java.util.Date;
import java.util.List;

/**
 * 留级记录Service业务层处理
 * 
 * @author lwj
 * @date 2024-01-24
 */
@Service
public class TransferRecordsServiceImpl implements ITransferRecordsService 
{
    @Autowired
    private TransferRecordsMapper transferRecordsMapper;

    @Autowired
    private ClassManageMapper classManageMapper;

    @Autowired
    private StudentManageMapper studentManageMapper;

    /**
     * 查询留级记录
     * 
     * @param studentId 留级记录主键
     * @return 留级记录
     */
    @Override
    public TransferRecords selectTransferRecordsByStudentId(Long studentId)
    {
        return transferRecordsMapper.selectTransferRecordsByStudentId(studentId);
    }

    /**
     * 查询留级记录列表
     * 
     * @param transferRecords 留级记录
     * @return 留级记录
     */
    @Override
    public List<TransferRecords> selectTransferRecordsList(TransferRecords transferRecords)
    {
        return transferRecordsMapper.selectTransferRecordsList(transferRecords);
    }

    /**
     * 新增留级记录
     * 
     * @param transferRecords 留级记录
     * @return 结果
     */
    @Override
    public int insertTransferRecords(TransferRecords transferRecords)
    {
        transferRecords.setCreateTime(new Date());
        Long classId = transferRecords.getClassId();
        ClassManage classManage = classManageMapper.selectClassManageById(classId);
        String className = classManage.getClassName();
        transferRecords.setClassName(className);

        StudentManage studentManage = studentManageMapper.selectStudentManageById(transferRecords.getStudentId());
        studentManage.setClassId(classId);
        studentManage.setClassName(className);
        studentManage.setStudentStatus(transferRecords.getStudentStatus());
        studentManage.setSchoolPosition(classManage.getSchoolPosition());
        studentManageMapper.updateStudentManage(studentManage);
        return transferRecordsMapper.insertTransferRecords(transferRecords);
    }

    /**
     * 修改留级记录
     * 
     * @param transferRecords 留级记录
     * @return 结果
     */
    @Override
    public int updateTransferRecords(TransferRecords transferRecords)
    {
        return transferRecordsMapper.updateTransferRecords(transferRecords);
    }

    /**
     * 批量删除留级记录
     * 
     * @param studentIds 需要删除的留级记录主键
     * @return 结果
     */
    @Override
    public int deleteTransferRecordsByStudentIds(Long[] studentIds)
    {
        return transferRecordsMapper.deleteTransferRecordsByStudentIds(studentIds);
    }

    /**
     * 删除留级记录信息
     * 
     * @param studentId 留级记录主键
     * @return 结果
     */
    @Override
    public int deleteTransferRecordsByStudentId(Long studentId)
    {
        return transferRecordsMapper.deleteTransferRecordsByStudentId(studentId);
    }
}
